﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web.DynamicData;
using System.Web.UI;

namespace Fatec.ControleEstoque.Attributes
{
    public class HideColumnFieldsManager : IAutoFieldGenerator
    {
        protected MetaTable _table;
        protected PageTemplate _currentPage;

        public HideColumnFieldsManager(MetaTable table, PageTemplate currentPage)
        {
            _table = table;
            _currentPage = currentPage;
        }

        public ICollection GenerateFields(Control control)
        {
            var oFields = new List<DynamicField>();

            foreach (var column in _table.Columns)
            {
                // carry on the loop at the next column  
                // if scaffold table is set to false or DenyRead
                if (!column.Scaffold ||
                    column.IsLongString ||
                    column.IsHidden(_currentPage))
                    continue;

                var f = new DynamicField();

                f.DataField = column.Name;
                oFields.Add(f);
            }
            return oFields;
        }
    }
}